
#include "lab3.h"
#include <iostream>  
#include<string>


using namespace std;  

void SortByFirstName( int numStudents, Student *pStudents )
{
	for ( int i = 0; i < numStudents; ++i )
	{
		for ( int j = i + 1; j < numStudents; ++j )
		{
			if ( strcmp( pStudents[i].GetFirstName(), pStudents[j].GetFirstName() ) > 0 )
			{
				Student tempStudent( pStudents[i] );
				pStudents[i] = pStudents[j];
				pStudents[j] = tempStudent;
			}
		}
	}
}

// TODO:
void SortByLastName( int numStudents, Student *pStudents )
{
	for ( int i = 0; i < numStudents; ++i )
	{
		for ( int j = i + 1; j < numStudents; ++j )
		{
			if ( strcmp(pStudents[i].GetLastNAme(), pStudents[j].GetLastNAme()) >0  )
			{
				Student tempStudent( pStudents[i] );
				pStudents[i] = pStudents[j];
				pStudents[j] = tempStudent;
			}
		}
	}
}

// TODO:
void SortByGrades( int numStudents, Student *pStudents )
{
	for ( int i = 0; i < numStudents; ++i )
	{
		for ( int j = i + 1; j < numStudents; ++j )
		{
			if ( pStudents[i].GetAverageGrade() > pStudents[j].GetAverageGrade() )
			{
				Student tempStudent( pStudents[i] );
				pStudents[i] = pStudents[j];
				pStudents[j] = tempStudent;
			}
		}
	}
}

void DisplayStudent( int numStudents, Student *pStudents  );


int main()
{	//char* 

	float grades[5][5] = {
		{ 70.0f, 65.0f, 85.0f, 100.0f, 95.0f },
		{ 50.0f, 94.0f, 45.0f, 98.0f, 91.0f },
		{ 40.0f, 86.0f, 85.0f, 74.0f, 93.0f },
		{ 20.0f, 73.0f, 87.0f, 60.0f, 86.0f },
		{ 60.0f, 65.0f, 89.0f, 65.0f, 89.0f },
	};

	Student stud[5] = {
		Student( "Brent", "Chua", 5, grades[0] ),
		Student( "Penguin", "Popper", 5, grades[1] ),
		Student( "Ronald", "Chua", 5, grades[2] ),
		Student( "Apple", "Bee", 5, grades[3] ),
		Student( "Michael", "Jackson", 5, grades[4] ),
	};

	
	SortByFirstName( 5, stud );
	DisplayStudent( 5, stud );
	cout<<endl<<endl;
	SortByLastName( 5, stud );
	DisplayStudent( 5, stud );
	cout<<endl<<endl;
	SortByGrades( 5, stud );
	DisplayStudent( 5, stud );



	//stud[0].display();
	//int Temp;
	//for(int x = 0;x<=4; ++x)
	//{
	//	for(int y = x+1; y<=4; ++y)
	//	{

	//		if(stud[x].GetGrade()) < (stud[y].GetGrade())
	//			Temp = stud[x].GetGrade();
	//		stud[x].GetGrade() = stud[y].GetGrade();
	//		stud[y].GetGrade() = e
	//	}
	//}
	return 0;
}


void DisplayStudent( int numStudents, Student *pStudents  )
{
	for ( int i = 0; i < numStudents; ++i )
		pStudents[i].display();
}
